home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-05-14 | 11.1 KB | 452 lines |
- import ComponentApp;
-
- public class FormHandlerComp extends ComponentApp
- {
- DAssetManager cam;
- DDrawFormButton cdp;
- int ImageID;
- int perlScriptID;
- String SubmitName;
- int SuccessURL;
- int ErrorURL;
- String outputFile; //should it be the whole path
-
- String UnixWindows;
- String PerlPath;
- String storageDir;
- String codeBase;
-
- static final int MAXASSET=50;
- boolean published = false;
- boolean reqField[];
- int reqFieldCount = 0;
-
- int assetControl[];
- int assetCount = 0;
- int tAssetCount = 0;
- int actionCGIAsset = 0;
-
- int min(int i, int j){
- if (i < j)
- return i;
- else
- return j;
- }
- int max(int i, int j){
- if (i > j)
- return i;
- else
- return j;
- }
-
- String cleanPath(String path){
-
- String temp = new String(path);
- String temp2 = new String(path);
- String temp3 = new String(path);
-
- int len = path.length();
- //sub to home
- if(temp.substring(0,3).compareTo("../") == 0){
- path = "../" + path;
- }
- //home to sub, sub to sub
- else if(temp2.substring(0,7).compareTo("../html") == 0){
- path = "../" + path;
- }
- //home to home
- else if(temp3.substring(0,2).compareTo("./") == 0){
- path = "../." + path;
- }
-
- return path;
-
-
-
- }
-
-
- String getFieldName(int i){
- int temp = i + 1;
- return "Required field "+ temp;
- }
-
-
- String getHiddenInsert(int context){
- String hold;
- // if (cam.GetAssetLocation(SuccessURL,context,IFileNameStyle.DosName).substring(0,4))
-
- hold = "<INPUT TYPE=\"HIDDEN\" NAME=\"success\" VALUE=\"" + cleanPath(cam.GetAssetLocation(SuccessURL,context,IFileNameStyle.DosName))+"\">\n";
- hold = hold + "<INPUT TYPE=\"HIDDEN\" NAME=\"error\" VALUE=\"" + cleanPath(cam.GetAssetLocation(ErrorURL,context,IFileNameStyle.DosName))+"\">\n";
-
-
- hold = hold + "<INPUT TYPE=\"HIDDEN\" NAME=\"fields\" VALUE=\"" + reqFieldCount + "\">\n";
- hold = hold + "<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" VALUE=\"" + outputFile + "\">\n";
- int tempK;
- for (int k=0; k < reqFieldCount; k++){
- if (reqField[k] == true){
- tempK = k + 1;
- hold = hold + "<INPUT TYPE=\"HIDDEN\" NAME=\"" + tempK + "a\" VALUE=\"TRUE\">\n";
- }
- }
- return hold;
-
- }
-
- int countElement()
- {
- IDLayout cidLayout = cdp.getLayout();
- int count = 1;
- boolean tempField[];
- int tempCounter = 0;
-
- while (true) {
- String name = new String() + count;
- if ( cidLayout.IsElementName(name) ) {
- ++count;
- continue;
- }
- else {
- count--;
- break;
- }
- }
-
- if (reqField == null){
- reqField = new boolean [count];
- for (tempCounter = 0; tempCounter < count; tempCounter++){
- reqField[tempCounter] = false;
- }
- reqFieldCount = count;
- return count;
- }
-
- int minCount = min(reqFieldCount,count);
-
- tempField = reqField;
- reqField = new boolean [count];
- //take the min of two.
-
- for (tempCounter = 0; tempCounter < minCount; tempCounter++){
- reqField[tempCounter] = tempField[tempCounter];
- }
- if (reqFieldCount != max(reqFieldCount, count)){
- //make sure new array is larger, so false setting is justify.
- //if old array, then skip this seciton.
- for (; tempCounter < max(reqFieldCount, count); tempCounter++){
- reqField[tempCounter] = false;
- }
- }
- //min to max.
- //initialize whatever have not been copy... which is false.
-
-
-
- reqFieldCount = count;
- return count;
- }
-
-
- public String onInstall(DAssetManager asm, String codeBaseOut)
- {
- // assetControl = new int [MAXASSET];
- cam = asm;
- codeBase = codeBaseOut;
- return "Form Handler";
- }
-
- public void onInspect(CStringArray Names, CStringArray Types)
- {
- Names.Set("Button Name");
- Types.Set(typeString);
- Names.Set("Success URL");
- Types.Set(typeLink);
- Names.Set("Error URL");
- Types.Set(typeLink);
- Names.Set("Output File");
- Types.Set(typeString);
- Names.Set("Publish to");
- Types.Set("Set(Windows|Unix|Mac)");
- Names.Set("Perl Path for Unix");
- Types.Set(typeString);
- // Names.Set("Storage Directory");
- // Types.Set(typeString);
- int tempCounter=countElement();
- for(int marker=0; marker < tempCounter; marker++){
- Names.Set(getFieldName(marker));
- Types.Set("Set(True|False)");
- }
-
- }
-
-
- public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp)
- {
- if (Get == 1)
- {
- if (Event.compareTo("Button Name") == 0)
- {
- return SubmitName;
- }
- else if (Event.compareTo("Success URL") == 0)
- {
- return Integer.toString(SuccessURL);
- }
- else if (Event.compareTo("Error URL") == 0)
- {
- return Integer.toString(ErrorURL);
- }
- else if (Event.compareTo("Output File") == 0)
- {
- return outputFile;
- }
- else if (Event.compareTo("Publish to") == 0)
- {
- if(UnixWindows.compareTo("Windows") == 0)
- return "0";
- else if (UnixWindows.compareTo("Unix") == 0)
- return "1";
- else if (UnixWindows.compareTo("Mac") == 0)
- return "2";
-
- }
- else if (Event.compareTo("Perl Path for Unix") == 0)
- {
- return PerlPath;
- }
- // else if (Event.compareTo("Storage Directory") == 0)
- // {
- // return storageDir;
- // }
-
- for(int marker=0; marker < countElement(); marker++){
- // marker++;
- if (Event.compareTo(getFieldName(marker)) == 0)
- {
- if( reqField[marker]==false ){
- return "1";
- }
- else {
- return "0";
- }
- }
- }
- }
- else
- {
- if (Event.compareTo("Button Name") == 0)
- {
- SubmitName = Value;
- cdp.setText(SubmitName);
- }
- else if (Event.compareTo("Success URL") == 0)
- {
- SuccessURL = Integer.parseInt(Value,10);
- }
- else if (Event.compareTo("Error URL") == 0)
- {
- ErrorURL = Integer.parseInt(Value,10);
- }
- else if (Event.compareTo("Output File") == 0)
- {
- outputFile = Value;
- }
- else if (Event.compareTo("Publish to") == 0)
- {
- // if(Value.compareTo("0")==0)
- // UnixWindows=true;
- //to unix
- // else
- // UnixWindows=false;
- //to window
- if (Value.compareTo("0") == 0)
- UnixWindows = "Windows";
- else if (Value.compareTo("1") == 0)
- UnixWindows = "Unix";
- else
- UnixWindows = "Mac";
-
-
- }
- else if (Event.compareTo("Perl Path for Unix") == 0)
- {
- PerlPath = Value;
- }
- // else if (Event.compareTo("Storage Directory(Unix)") == 0)
- // {
- // storageDir = Value;
- // }
-
- for(int marker=0; marker < countElement(); marker++){
-
- if (Event.compareTo(getFieldName(marker)) == 0)
- {
- if(Value.compareTo("0")==0)
- {
- reqField[marker]=true;
- }
- else {
- reqField[marker]=false;
- }
- }
- }
-
- }
- return "";
- }
-
-
-
- public void onCopy()
- {
-
- SubmitName = new String(SubmitName);
- outputFile = new String(outputFile); //should it be the whole path
- PerlPath = new String(PerlPath);
- storageDir = new String(storageDir);
- codeBase = new String(codeBase);
-
- boolean [] temp = new boolean[reqFieldCount];
-
- for (int i=0; i < reqFieldCount; i++)
- temp[i] = reqField[i];
-
- reqField = temp;
-
-
- for(tAssetCount = 0; tAssetCount < assetCount; tAssetCount++){
- cam.CopyAsset(assetControl[tAssetCount]);
- }
-
-
-
-
-
-
- }
-
- public void onDrop(IDLayout layout, IDRect r, int fDrop)
- {
-
- //
- // we only process drop for now
- //
- if (fDrop != ActivateState.Drop)
- return;
-
- assetControl = new int [MAXASSET];
- for (int tCount = 0; tCount < MAXASSET; tCount++){
- assetControl[tCount] = 0;
- }
-
-
- DFile theScript = new DFile();
- // String FusionPath = cdp.getCodeBase();
- // String FusionPath = theScript.getExeLocation() + "NetObjects System\\Components\\FormHandlerComp\\";
- String FusionPath = codeBase;
-
- //need to get # of form elements from David
-
- SubmitName="Submit";
- outputFile="webinfo";
- UnixWindows="Windows";
- PerlPath="/usr/local/bin/perl";
- storageDir="../webdata/";
-
- cdp = new DDrawFormButton();
- cdp.setText(SubmitName);
- layout.AddObject(cdp);
-
- cdp.SetPositionRect(r.getLeft(), r.getTop(), r.getRight(), r.getBottom());
- }
-
-
- protected void finalize(){
-
- if (published == true){
- for(tAssetCount = 0; tAssetCount < assetCount; tAssetCount++){
- cam.RemoveAsset(assetControl[tAssetCount]);
- }
-
- }
-
-
- }
-
-
- public void onPublish(DAssetManager asm, int context)
- {
- IDLayout cidLayout = cdp.getLayout();
- int count = countElement();
-
- DFile file = new DFile();
- DFile fileFrom = new DFile();
-
- DFile theScript = new DFile();
- String FusionPath = codeBase;
- String pathChar = theScript.GetPathChar();
-
- DMessageBox mBox = new DMessageBox();
-
- if (published == true){
- for(tAssetCount = 0; tAssetCount < assetCount; tAssetCount++){
- cam.RemoveAsset(assetControl[tAssetCount]);
- }
- }
- assetCount = 0;
- published = true;
-
-
- cdp.setHTMLBefore(this.getHiddenInsert(context));
-
- if(UnixWindows.compareTo("Windows") == 0){
- //NT version
-
- actionCGIAsset = cam.AddAsset(FusionPath+"Forms" + pathChar + "cgi-bin-NT" + pathChar + "Forms-Handler.cgi", IAssetType.CGI,"assets" + pathChar + "cgi-bin");
- assetControl[assetCount] = actionCGIAsset;
- cam.SetPublishAssetMode(assetControl[assetCount++], 0705);
- assetControl[assetCount] = cam.AddAsset(FusionPath+"Forms" + pathChar + "cgi-bin-NT" + pathChar + "Buf.dll", IAssetType.CGI,"assets" + pathChar + "cgi-bin");
- cam.SetPublishAssetMode(assetControl[assetCount++], 0705);
- }
- if(UnixWindows.compareTo("Mac") == 0){
- //Mac version
-
- actionCGIAsset = cam.AddAsset(FusionPath+"Forms" + pathChar + "cgi-bin-mac" + pathChar + "Forms-Handler.cgi", IAssetType.CGI,"assets" + pathChar + "cgi-bin");
- assetControl[assetCount] = actionCGIAsset;
- cam.SetPublishAssetMode(assetControl[assetCount++], 0705);
- assetControl[assetCount] = cam.AddAsset("assets" + pathChar + "webdata" + pathChar + "",IAssetType.SubDir, "");
- cam.SetPublishAssetMode(assetControl[assetCount++], 0703);
- }
- else {
- //Unix version
-
- assetControl[assetCount] = cam.AddAsset("assets" + pathChar + "webdata" + pathChar + "",IAssetType.SubDir, "");
- cam.SetPublishAssetMode(assetControl[assetCount++], 0703);
-
-
- fileFrom.Open(FusionPath+"Forms" + pathChar + "cgi-bin-Unix" + pathChar + "Forms-Handler.cgi",FileOpenMode.modeRead);
- file.Open(FusionPath+"Forms" + pathChar + "cgi-bin" + pathChar + "Forms-Handler.cgi",FileOpenMode.modeWrite|FileOpenMode.modeCreate);
- file.WriteString("#!"+PerlPath+"\n", -1);
- file.WriteString("$STORAGEDIR=\""+storageDir+"\";", -1);
- file.WriteString(fileFrom.ReadString(10000),-1);
- file.Close();
- fileFrom.Close();
- actionCGIAsset = cam.AddAsset(FusionPath+"Forms" + pathChar + "cgi-bin" + pathChar + "Forms-Handler.cgi", IAssetType.CGI,"assets" + pathChar + "cgi-bin");
- assetControl[assetCount] = actionCGIAsset;
- cam.SetPublishAssetMode(assetControl[assetCount++], 0705);
-
-
- }
-
-
-
- String cgiPath = cam.GetAssetRelativeLocation(actionCGIAsset, context, IFileNameStyle.HTMLName);
-
-
-
- cidLayout.setFormAction(cgiPath);
-
- }
-
-
- }